export default {
	data() {
		return {
			cWidth: 0,
			cHeight: 0,
			canvas: true,
			arr: [],
			categories: [],
			series: [],
			transaction_time: 30,
			serverData: {
				chartType: "line",
				extraType: "curve",
				id: "order_total",
				opts: {

				}
			}
		}
	},
	methods: {
		init() {
			this.cWidth = uni.upx2px(690);
			this.cHeight = uni.upx2px(540);
			this.getServerData();
		},
		getServerData() {
			var Data = {
				enableScroll: false,
				yAxisdisabled: true,
				xAxisgridColor: 'transparent',
				yAxisgridType: 'dash',
				yAxisgridColor: '#eeeeee',
				animation: true,
				enableScroll: true,
				scrollColor: 'transparent',
				scrollPosition: 'right',
				scrollBackgroundColor: 'transparent',
				categories: [...this.categories],
				series: [...this.series],
				extra: {
					area: {
						addLine: true,
						opacity: 0.5,
						width: 2,
						color: '#FF6A00',
						type: 'curve'
					},
				},
				legend: true
			}
			this.serverData = {
				...this.serverData,
				opts: Data
			};
		},
		// X数字资产价值（图表）
		getChartData() {
			return new Promise((resolve, reject) => {
				let url = '/goldpoints/api/Record/getXvalueLineChart';
				if (this.selectIndex == 1 || this.selectIndex == 2) {
					url = '/goldpoints/api/Record/getPointsLineChart';
				}
				let data = {
					time: this.statistics_type
				};
				if (this.selectIndex == 1 || this.selectIndex == 2) {
					let type = '0';
					if (this.selectIndex == 2) {
						type = '1';
					}
					data = {
						time: this.statistics_type,
						type: type
					}
				}
				this.$api.sendRequest({
					url: url,
					data: data,
					success: (res) => {
						if (res.code == 0) {
							let date = [];
							this.categories = [];
							this.series = [];
							res.data.list.forEach(item => {
								date.push(item.date)
							})
							this.categories = date;

							let x_values = [];
							if (this.selectIndex == 0) {
								this.showStr = res.data.x_value;
								res.data.list.forEach(item => {
									x_values.push(item.money);
								})
								this.series = [{
									name: 'X数字资产价值',
									data: x_values,
									color: '#12D0AE',
									time: this.categories
								}];
							} else {
								this.showStr = res.data.currently;
								res.data.list.forEach(item => {
									x_values.push(item.value);
								})
								if (this.selectIndex == 1) {
									this.series = [{
										name: '数量池',
										data: x_values,
										color: '#12D0AE',
										time: this.categories
									}];
								} else {
									this.series = [{
										name: '分红池',
										data: x_values,
										color: '#12D0AE',
										time: this.categories
									}];
								}
							}
							this.init();
							this.$refs.order_total.changeData(this.serverData.id, this.serverData
								.opts);
							resolve(res.data)
						} else {
							this.$util.showToast({
								title: res.message
							});
							reject(res)
						}
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					fail: err => {
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				})
			})
		}
	}
}